package com.htudata.flow.dao;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.List;

import com.htudata.flow.mapper.FlowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class FlowDao {
  @Autowired
  private FlowMapper flowMapper;
  
  public JSONArray getInternal3DFlowsInfo(String flowStatuses) {
    JSONObject params = new JSONObject();
    params.put("flowStatuses", flowStatuses.split(","));
    return this.flowMapper.getInternal3DFlowsInfo(params);
  }
  
  public JSONArray selectFlowIdByUser(long userId) {
    JSONObject params = new JSONObject();
    params.put("userId", Long.valueOf(userId));
    return this.flowMapper.selectFlowIdByUser(params);
  }
  
  public JSONArray selectNodeIdByUser(long userId) {
    JSONObject params = new JSONObject();
    params.put("userId", Long.valueOf(userId));
    return this.flowMapper.selectNodeIdByUser(params);
  }
  
  public int updateFlowEditStatus(String flowId, int editStatus) {
    return this.flowMapper.updateEditStatus(flowId, editStatus);
  }
  
  public JSONObject getFlowHealthStatis(String flowId) {
    return this.flowMapper.getFlowHealthStatis(flowId);
  }
  
  public JSONObject getNodeHealthStatis(String nodeId) {
    return this.flowMapper.getNodeHealthStatis(nodeId);
  }
  
  public JSONArray getNodeLeaderBoard(String flowId, int year, String field, String sort, int page, int perPage, List<Long> userIds) {
    if (page == 0 && perPage == 0)
      perPage = -1; 
    return this.flowMapper.getNodeLeaderBoard(flowId, year, field, sort, page, perPage, userIds);
  }
  
  public JSONArray getItemLeaderBoard(String flowId, String nodeId, int year, String field, String sort, int page, int perPage, List<Long> userIds) {
    if (page == 0 && perPage == 0)
      perPage = -1; 
    return this.flowMapper.getItemLeaderBoard(flowId, nodeId, year, field, sort, page, perPage, userIds);
  }
}
